<?php

    namespace app\admin\controller;
    use think\Controller;
    use app\admin\model\Student;
    use app\admin\model\Classes;
    use think\Request;
    use think\Db;

    class Suser extends Controller{


        public function index(){
            //学生列表信息volist
            $role = New Student();
            $data = $role -> s_list();
            //dump($data->toArray());
            $this->assign('s_list',$data);

            //修改学生里面的班级volist
            $classes = New Classes();
            $classdata = $classes -> classno_list();
            // dump($classdata->toArray());
            $this->assign('classno_list',$classdata);

            //新添学生里面的班级volist
            $classes = New Classes();
            $newclassdata = $classes -> newclassno_list();
            // dump($newclassdata->toArray());
            $this->assign('newclassno_list',$newclassdata);

            return $this->fetch();
        }

        public function suserdelete(Request $Request){
            $id = request()->param();
            // var_dump($id);
            
            $res = DB::table("student")->delete($id);
            if($res){
                $this->success("OK","admin/suser/index");
            }else{
                $this->error();
            }
        }

        public function suserinsert(){
            if(request()->isPost()){
                $student=new Student();
                $data=input('post.');
                // var_dump($data);
                $num=$student->insert($data);
                if($num==1){
                    $this->success("新添成功","admin/suser/index");
                }else{
                    $this->error('新添失败');
                }
            }
            return $this->fetch();
        }
        //修改信息
        public function suserupdata(){
            if(request()->isPost()){
                $student=new Student();
                $data=input('post.');
                // var_dump($data);
                $num=$student->updata($data);
                
                if($num==1){
                    $this->success("修改成功","admin/suser/index");
                }else{
                    $this->error('修改失败');
                }
            }
            return $this->fetch();
        }

    }

?>